package com.sntk.registermanager.staff.infrastructure.convert;

import com.sntk.registermanager.staff.domain.model.DoctorInfo;
import com.sntk.registermanager.staff.domain.model.Gender;
import com.sntk.registermanager.staff.infrastructure.db.entity.DoctorInfoEntity;
import org.springframework.stereotype.Component;
import org.springframework.util.ObjectUtils;

/**
 * @author liuyunxia
 */
@Component
public class DoctorInfoConvert {

    public DoctorInfoEntity convert(DoctorInfo doctorInfo){

        if(ObjectUtils.isEmpty(doctorInfo)){
            return null;
        }

        DoctorInfoEntity entity = new DoctorInfoEntity();

        entity.setId(doctorInfo.getId())
        .setDoctorCode(doctorInfo.getDoctorCode())
        .setDoctorName(doctorInfo.getDoctorName())
        .setIntroduction(doctorInfo.getIntroduction())
        .setPhone(doctorInfo.getPhone())
        .setRemark(doctorInfo.getRemark())
        .setUname(doctorInfo.getUname())
        .setVersion(doctorInfo.getVersion())
        .setGender(doctorInfo.getGender() == null ? null : doctorInfo.getGender().getIndex())
        .setDisabled(doctorInfo.getDisabled())
        .setImgSrc(doctorInfo.getImgSrc())
        .setJobTitle(doctorInfo.getJobTitle());

        return entity;
    }


    public DoctorInfo convert(DoctorInfoEntity entity){

        if(ObjectUtils.isEmpty(entity)){
            return null;
        }
        return new DoctorInfo(entity.getId(),
                entity.getDoctorCode(),
                entity.getDoctorName(),entity.getPhone(),
                entity.getIntroduction(),
                entity.getRemark(),
                entity.getDisabled(),
                entity.getJobTitle(),
                entity.getUname(),
                Gender.get(entity.getGender()),
                entity.getImgSrc(),
                entity.getVersion());
    }


}
